﻿using System;
using System.Windows;

namespace TallyJ1Announcer.VoterRelated
{
	public class Voter : DependencyObject, IEquatable<Voter>, IComparable<Voter>
	{
		
	
		public static readonly DependencyProperty DisplayNameProperty =
			DependencyProperty.Register("DisplayName", typeof (string), typeof (Voter));

		public static readonly DependencyProperty VotingMethodProperty =
			DependencyProperty.Register("VotingMethod", typeof (string), typeof (Voter));

		public static readonly DependencyProperty DisplayDateProperty =
			DependencyProperty.Register("DisplayDate", typeof (DateTime), typeof (Voter));

		public static readonly DependencyProperty LoadDateProperty =
			DependencyProperty.Register("LoadDate", typeof (DateTime), typeof (Voter));

		public Voter(string displayName, string votingMethod, string uniqueCode, bool isBlank)
		{
			DisplayName = displayName;
			VotingMethod = votingMethod;
			UniqueCode = uniqueCode;
			IsBlank = isBlank;
			LoadDate = DateTime.Now;
			HasBeenDisplayed = false;
		}

		public string UniqueCode { get; private set; }
		public bool IsBlank { get; set; }
		public bool HasBeenDisplayed { get; set; }

		public string DisplayName
		{
			get { return (string) GetValue(DisplayNameProperty); }
			set { SetValue(DisplayNameProperty, value); }
		}

		public string VotingMethod
		{
			get { return (string) GetValue(VotingMethodProperty); }
			set { SetValue(VotingMethodProperty, value); }
		}

		public DateTime DisplayDate
		{
			get { return (DateTime) GetValue(DisplayDateProperty); }
			set
			{
				HasBeenDisplayed = true;
				SetValue(DisplayDateProperty, value);
			}
		}

		public DateTime LoadDate
		{
			get { return (DateTime) GetValue(LoadDateProperty); }
			set { SetValue(LoadDateProperty, value); }
		}

		#region IComparable<Voter> Members

		public int CompareTo(Voter other)
		{
			return other.UniqueCode.CompareTo(UniqueCode);
		}

		#endregion

		#region IEquatable<Voter> Members

		public bool Equals(Voter other)
		{
			return other.UniqueCode == UniqueCode;
		}

		#endregion

		public static bool operator >(Voter n1, Voter n2)
		{
			return n1.UniqueCode.CompareTo(n2.UniqueCode) > 0;
		}

		public static bool operator <(Voter n1, Voter n2)
		{
			return n1.UniqueCode.CompareTo(n2.UniqueCode) < 0;
		}

		public override string ToString()
		{
			return DisplayName;
		}
	}
}